import 'package:flutter/material.dart';

import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGButton.dart';

class QGSendNFTAlert extends StatefulWidget {
  String title;
  String content;
  String cancel;
  String confirm;
  void Function()? onCancel;
  void Function(String?)? onConfirm;
  BuildContext context;

  QGSendNFTAlert({
    super.key,
    required this.context,
    required this.title,
    required this.content,
    required this.cancel,
    required this.confirm,
    this.onCancel,
    this.onConfirm,
  });

  static show(context,
      {title = '商品转赠',
      content = "一旦转赠成功将无法找回，请谨慎操作",
      cancel = "取消",
      confirm = "确定",
      onCancel,
      onConfirm}) {
    showDialog(
        context: context,
        builder: (context) {
          return QGSendNFTAlert(
              context: context,
              title: title,
              content: content,
              cancel: cancel,
              confirm: confirm,
              onCancel: onCancel,
              onConfirm: onConfirm);
        });
  }

  @override
  State<QGSendNFTAlert> createState() => _QGSendNFTAlertState();
}

class _QGSendNFTAlertState extends State<QGSendNFTAlert> {
  var controller = TextEditingController();

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        GestureDetector(
          onTap: () {
            unfocus(context);
          },
          child: Container(
            margin: EdgeInsets.symmetric(horizontal: 25.rpx),
            padding: EdgeInsets.symmetric(horizontal: 20.rpx, vertical: 25.rpx),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(20.rpx),
              color: Color(0xFF232A32),
            ),
            child: Column(mainAxisSize: MainAxisSize.min, children: [
              buildHeader(),
              SizedBox(height: 25.rpx),
              buildButtons(),
            ]),
          ),
        ),
      ],
    );
  }

  buildHeader() {
    return Column(
      children: [
        Text(
          widget.title,
          style: TextStyle(
              color: Color(0xFFffffff),
              fontSize: 16.rpx,
              fontWeight: FontWeight.bold),
        ),
        SizedBox(height: 25.rpx),
        buildInput(),
        SizedBox(height: 15.rpx),
        Text(
          widget.content,
          style: TextStyle(
              color: Color(0xFF989EA4),
              fontSize: 14.rpx,
              fontWeight: FontWeight.normal),
        ),
      ],
    );
  }

  buildInput() {
    return Container(

      padding: EdgeInsets.symmetric(horizontal: 15.rpx),
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            color: Color(0XFF3D4854)
          )
        ),
        color: Color(0xFF232A32),
      ),
      child: TextField(
          textAlign: TextAlign.center,
          controller: controller,
          keyboardType: TextInputType.number,
          textInputAction: TextInputAction.done,
          cursorColor: Color(0xFFffffff),
          // autofocus: phoneController.text.isEmpty,
          style: TextStyle(
              color: Color(0xFFffffff),
              fontSize: 14.rpx,
              fontWeight: FontWeight.normal),
          decoration: InputDecoration(
            hintText: "输入对方钱包地址",
            hintStyle: TextStyle(color: Color(0xFF999999)),
            enabledBorder: InputBorder.none,
            focusedBorder: InputBorder.none,
          )),
    );
  }

  buildButtons() {
    return SizedBox(
      height: 120.rpx,
      child: Column(
        children: [
            QGButton(title: widget.confirm, enable: true, onTap: onTap),
            SizedBox(height: 15.rpx),
QGOutlineButton(
                  title: widget.cancel,
                  enable: true,
                  onTap: () {
                    if (widget.onCancel != null) {
                      widget.onCancel!();
                    } else {
                      Navigator.of(widget.context).pop();
                    }
                  }),

          // Expanded(

          //     child: QGOutlineButton(
          //         title: widget.cancel,
          //         enable: true,
          //         onTap: () {
          //           if (widget.onCancel != null) {
          //             widget.onCancel!();
          //           } else {
          //             Navigator.of(widget.context).pop();
          //           }
          //         })),
          // SizedBox(width: 15.rpx),
          // Expanded(
          //     child:
          //         QGButton(title: widget.confirm, enable: true, onTap: onTap)),
        ],
      ),
    );
  }

  onTap() {
    unfocus(context);
    if (controller.text.isEmpty) {
      toast("请输入对方钱包地址");
      return;
    }
    if (widget.onConfirm != null) {
      widget.onConfirm!(controller.text);
    } else {
      Navigator.of(widget.context).pop();
    }
  }
}
